package com.example.unisys.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.unisys.entity.User;
import com.example.unisys.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserService extends ServiceImpl<UserMapper,User> {


    public User getUserByName(String username){
        User user= baseMapper.selectOne(new QueryWrapper<User>().lambda().eq(User::getUsername,username));
        return user;
    }

    public String getPassWord(String username) {
        return baseMapper.getPassWord(username);
    }

    public User getInfo(String username) {
        return baseMapper.getInfo(username);
    }

    public int updateip(String ip, int user_id) {
        return baseMapper.updateip(ip, user_id);
    }

    public List<User> getAdminsBySchool(Map map){
        return baseMapper.getAdminsBySchool(map);
    }
    public Integer getAdminSumBySchool(Map map){
        return baseMapper.getAdminSumBySchool(map);
    }
    //public int getUserType(String username){return baseMapper.getUserType(username);}

    public int insert(User user){
        return baseMapper.insertSelective(user);
    }

    public int delete(int user_id){
        return baseMapper.delete(user_id);
    }

    public int update(User user){
        return baseMapper.update(user);
    }

    public int updatetime(int user_id,String prev_time){
        return baseMapper.updatetime(user_id,prev_time);
    }

    public List<User> getAdmins(HashMap<String, Object> hs) {
        return baseMapper.getAdmins(hs);
    }

    public int getAdminSumBySystem(HashMap<String, Object> hs) {
        return baseMapper.getAdminSumBySystem(hs);
    }

    public String getPWDbyCondition(HashMap<String, Object> hs) {
        return baseMapper.getPWDbyCondition(hs);
    }
}
